<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>类的基本知识</title>
</head>
<body>
    <script type="text/javascript">
        //创建一个person类
        class Person{
            constructor(name,age){
                this.name = name;
                this.age = age;
            }
            //通过Person实例调用speak时,speak中的this就是person实例
            speak(){
                console.log(`${this.name}今年${this.age}岁`);
            }
        }
        //创建一个对象
        let p1 = new Person('小明',18);
        let p2 = new Person('小红',19);

        console.log(p1);
        console.log(p2);
    </script>

</body>
</html>